const Mock = require('mockjs')
export default {
  getList(map = {}) {

    console.log(map);

    return new Promise((resolve, reject) => {

      //返回分页数据
      let mockOption = {
        errno: 0,
        errmsg: '获取信息成功',
        data: {
          count: 28,
          totalPages: 3,
          pageSize: () => {
            return parseInt(map.pageSize || 5);
          },
          currentPage: () => {
            return parseInt(map.page || 1);
          },
          'data|10': [{
            'id': '@increment()',
            // "title": "雨伞", //项目名称
            title: () => {
              if (map.key) {
                return map.key
              } else {
                return "雨伞"
              }
            },
            'name': '@cname()',
            "address": "广州番禺职业技术学院6号楼6517",
            "telphone": /^1[345789]\d{9}$/,
            "images": ["@image('200x200')", "@image('200x200')", "@image('200x200')"],
            // "type|1": ["丢失", "捡到"],
            "type": () => {
              if (map.type == "" || map.type == '全部') {
                let list = ["丢失", "捡到"];
                return list[Mock.Random.integer(0, list.length - 1)];
              } else {
                return map.type
              }
            },
            "date": "@date()"
          }]
        }
      }

      resolve(Mock.mock(mockOption))
    });
  },

  getInfo(id, map = {}) {
    return new Promise((resolve, reject) => {
      let mockOption = {
        errno: 0,
        errmsg: '获取信息成功',
        'data': {
          'id': '@increment()',
          // "title": "雨伞", //项目名称
          title: () => {
            if (map.key) {
              return map.key
            } else {
              return "雨伞"
            }
          },
          'name': '@cname()',
          "address": "广州番禺职业技术学院6号楼6517",
          "telphone": /^1[345789]\d{9}$/,
          "images": ["@image('200x200')", "@image('200x200')", "@image('200x200')"],
          // "type|1": ["丢失", "捡到"],
          "type": () => {
            if (map.type == "" || map.type == '全部') {
              let list = ["丢失", "捡到"];
              return list[Mock.Random.integer(0, list.length - 1)];
            } else {
              return map.type
            }
          },
          "date": "@date()"
        }
      }
      resolve(Mock.mock(mockOption))
    })
  },
}
